package com.zues.thread.single_instance;

import lombok.extern.slf4j.Slf4j;

/**
 * 单例模式测试
 *
 * @author zues
 * @date 12/7/2024 11:08 下午
 */
@Slf4j(topic = "c.SingleTest")
public class SingleTest {

    public static void main(String[] args) {
        //校验为单例
//        Bank instance = Bank.getInstance();
//        Bank instance2 = Bank.getInstance2();
//        log.info("instance == instance2 = {}", instance==instance2);

        //同步方法
        new Thread(() -> {
            Bank instance = Bank.getInstance();
            log.info("instance = {}", instance);
        }).start();

        //同步代码块
        new Thread(() -> {
            Bank instance = Bank.getInstance2();
            log.info("instance2 = {}", instance);
        }).start();


    }

}
